package com.sshc625.utils {
	
	import flash.utils.Dictionary;
	
	public class SingletonFactory {
		
		private static var instances:Dictionary = new Dictionary( false );	
		
		/**
		 * Used to create a singleton from a class without adapting the 
		 * class itself. This function returns the same instance of the
		 * class every time it is called. This function only works with
		 * classes that don't require parameters in the constructor.
		 * 
		 * @param type The class you want a singleton from
		 * 
		 * @return the singleton instance of the class
		 */
		public static function createObject( type:Class, ...parameters ):* {
			return (type in instances) ? instances[type] : instances[type] = construct(type, parameters);
		}
		
		public static function getObject(type:Class):* {
			return instances[type];
		}
		
		public static function disposeObject(type:Class):void {
			instances[type] = null;
		}
	}
}